package com.service.Impl;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class BallService implements InvocationHandler {
    /**
     * 被代理的目标对象
     * @param o
     * @param method
     * @param objects
     * @return
     * @throws Throwable
     */
    private Object ball;
    public void setBall(Object ball) {
        this.ball = ball;
    }
    /**
     * 为被代理的接口定义代理规则
     * @param o
     * @param method
     * @param objects
     * @return
     * @throws Throwable
     */
    @Override
    public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
        System.currentTimeMillis();
        before();
        Object back = method.invoke(ball,objects);
        after();
        System.currentTimeMillis();
        return back;
    }
    public void before(){
        System.out.println("先做好热身运动");
    }
    public void after(){
        System.out.println("回家吃饭！");
    }
}
